package com.bjsxt.userCenter.common.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 * 模拟浏览器请求任何一个网址
 * 
 * @author WangshSxt
 *
 */
public class HttpUtil
{
	/**
	 * 输入一个url,
	 * 返回这个url对应的html代码
	 * 
	 * @param url:网址
	 * @return 返回网址对应的html代码
	 */
	public String methodGet(String urlStr)
	{
		ConstatFinalUtil.SYS_LOGGER.info("===methodGet===url:{}",urlStr);
		StringBuffer sb = new StringBuffer();
		try
		{
			URL url =  new URL(urlStr);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			InputStream is = connection.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
			String line ="";
			while((line = br.readLine())!=null)
			{
				sb.append(line);
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}
		return sb.toString();
	}
	
	public static void main(String[] args)
	{
		HttpUtil httpUtil = new HttpUtil();
		String url ="http://localhost:8080/userCenter-back/outer/json/verfiyToken.htm?json={%22version%22:%221%22,%22date%22:{%22token%22:%225f37d906-90cd-427e-96d5-320e761ee6c7%22}}";
		String res = httpUtil.methodGet(url);
		System.out.println(res);
	}
}
